﻿define(['util', 'ajax'], function (util, ajax) {
    "use strict";

    var exports = {},
         ViewModel;  

    ViewModel = function (model) {
        var self = this;
        var data = model.detail;
        
        var canvas = document.getElementById("imgCanvas");
        util.image.drawImage(canvas, util.image.checkOrDefault(data.imageData));

        self.id = ko.observable(data.id);
        self.tagId = ko.observable(data.tagId);
        self.name = ko.observable(data.name);
        self.dateOfBirth = ko.observable(moment(data.dateOfBirth).format("MM-DD-YYYY"));
        self.address = ko.observable(data.address);
        self.email = ko.observable(data.email);
        self.mobile = ko.observable(data.mobile);
        self.sendEmail = ko.observable(data.sendEmail);
        self.sendSms = ko.observable(data.sendSms);
        self.usePrint = ko.observable(data.usePrint);
        self.code = ko.observable(data.code);
        self.validFrom = ko.observable(moment(data.validFrom).format("MM-DD-YYYY"));
        self.validTo = ko.observable(moment(data.validTo).format("MM-DD-YYYY"));
        self.block = ko.observable(data.block);
        self.failedAttemptCount = ko.observable(data.failedAttemptCount);
        self.roleName = ko.observable(data.roleName);
        self.userStatusName = ko.observable(data.userStatusName);
        self.lastLoginTime = data.lastLoginTime == null ? '-' : ko.observable(moment(data.lastLoginTime).format("MM-DD-YYYY hh:mm"));
        self.lastPasswordChangedDate = data.lastPasswordChangedDate == null ? '-' : ko.observable(moment(data.lastPasswordChangedDate).format("MM-DD-YYYY hh:mm"));        
        
        self.auditHtml = ko.computed(function () {
            return data.createdByName + " " + moment(data.createdOn).format("MM-DD-YYYY hh:mm") + "(" + data.revisionNumber + ")";
        });       
    };

    exports.exec = function (sectionId, model) {        
        var viewModel = new ViewModel(model);
        ko.applyBindings(viewModel, document.getElementById(sectionId));
    };

    return exports;
});